package br.com.projeto.dao.jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import br.com.projeto.sakila.bean.Inventory;
import br.com.projeto.sakila.bean.Language;

public class LanguageDao {
	
	public long buscarLanguage(Connection connection){
		long tempoInicial = System.currentTimeMillis();
		
		try {
			PreparedStatement preparedStatement = 
					connection.prepareStatement("select language_id, name, last_update from language");
			
			ResultSet resultSet = preparedStatement.executeQuery();
			List<Language> lista = new ArrayList<>();
			Language obj;
			while(resultSet.next()){
				obj = null;
				obj = new Language();
				obj.setId(Byte.parseByte(resultSet.getString("language_id")));
				obj.setNome(resultSet.getString("name"));
				obj.setLastUpdate(resultSet.getDate("last_update"));
				
				lista.add(obj);
			}
			
			resultSet.close();
			preparedStatement.close();
			
		} catch (SQLException exception) {
			System.err.println("Erro JDBC" + exception);
			throw new RuntimeException(exception);
		}
		
		long tempoFinal = System.currentTimeMillis(); 
		long tempo = tempoFinal - tempoInicial;
		return tempo;
	}

}
